#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct act {
    int b, e;
};
vector<act> a;

bool cmp (act a, act b) {
    return a.e < b.e;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int b, e;
        cin >> b >> e;
        a.push_back({b, e});
    }
    sort(a.begin(), a.end(), cmp);
    int cnt = 0, end = 0;
    for(int i=0; i<n; i++) {
        if(a[i].b >= end) {
            cnt++;
            end = a[i].e;
        }
    }
    cout << cnt << endl;

    return 0;
} 